#include<iostream>
#include<cstdlib>
#include<algorithm>
const int N = 1e6 + 10;
int a[N];
using namespace std;
int main()
{
	int n;cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	sort(a + 1, a + 1 + n);
	int mid = (n / 2);
	int sum = 0;
	for (int i = 1; i <= n; i++)
	{
		sum += abs(a[mid] - a[i]);
	}
	cout << sum << endl;
		return 0;
}